Save As Excel file

I have a string output (buffer) and want to paste this into an excel file in a file location. Then 'Save As' with a new filename appended with datetime stamp. Note this excel has a macro that I would like to preserve in the new saved copy. Please help with some working code snippet. Thanks!
RPriy - Wed Nov 16 15:42:13 EST 2011

Re: Save As Excel file
Mathias Mamsch - Wed Nov 16 16:11:15 EST 2011

There are several posts on exporting to excel. See if you can find what you are searching for using the forum search. If you have problems, just check back here. Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Save As Excel file
SystemAdmin - Thu Nov 17 03:22:11 EST 2011

There is a nice exel example in DOORS lib, here is small part of it:

/*
 * This funciton saves the file as the passed in file name.
 */
void saveFileAs(string filename) {
    if(!fileOpen) {
                io4log << "ERRO : File not open\n";
                halt;
        }
        clear(args);
        put(args, "FileName", filename);
        
        checkRes(oleMethod(objWorkbook, "SaveAs", args))
        io4log << "INFO : File saved as " filename "\n";
}


and for the good file name with date-time here is some code which I used (thanks to this forum again) with minor changes:

 

string ZeroPrefixedInt(int i)
{
    string s = i ""
        if (i < 10)
        s = "0" s
        return s
}
 
string getZeroPrefixedTime()
{
        int now = intOf(dateAndTime(today))
        Date d = dateOnly(today)
        int day = intOf(date(stringOf(d)))
        int diff = now-day
        int hours = diff / 3600
        int mins = (diff - (3600 * hours)) / 60
        int secs = diff - (hours * 3600) - (mins * 60)
        
        return(ZeroPrefixedInt(hours) ZeroPrefixedInt(mins) ZeroPrefixedInt(secs))
 
}


here is the call:

 

 

string FileTimeStamp = stringOf(today,"yyyyMMdd") "-" getZeroPrefixedTime()
string fname_ExcelExport = "DOORS_ExcelExport_" FileTimeStamp ".xls"
saveFileAs(fname_ExcelExport)